package main

import (
	"fmt"
	service2 "github.com/kardianos/service"
	"github.com/sirupsen/logrus"
	"miao-va-host/daemon/service"
	"miao-va-host/global"
	"miao-va-host/lib/log"
	"os"
)

func main() {
	global.InitConfig()
	log.InitLog(global.Conf.Log.Name, global.Conf.Log.Lv)
	manager, err := service.New()
	if err != nil {
		logrus.Error(err)
		return
	}
	if len(os.Args) == 1 {
		if err = manager.Run(); err != nil {
			logrus.Error(err)
			return
		}
		return
	}
	switch os.Args[1] {
	case "-help":
		fallthrough
	case "-h":
		fmt.Println("install  安装服务 ")
		fmt.Println("uninstall  卸载服务 ")
		fmt.Println("start  启动服务 ")
		fmt.Println("stop  停止服务 ")
	default:
		err = service2.Control(manager, os.Args[1])
		if err != nil {
			logrus.Error(err)
		}
	}
}
